package com.situ.library.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.situ.library.pojo.vo.StatusCountVO;
import com.situ.library.service.IStatusService;
import com.situ.library.service.impl.StatusServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/status")
public class StatusServlet extends HttpServlet {
    private IStatusService statusService = new StatusServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method) {
            case "selectStatusCount":
                selectStatusCount(req, resp);
                break;
        }
    }

    private void selectStatusCount(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("StatusServlet.selectStatusCount");
        List<StatusCountVO> list = statusService.selectStatusCount();

        resp.setContentType("text/html;charset=UTF-8");
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(resp.getWriter(), list);
    }
}
